from rest_framework import serializers

from users.serializers import CreateUserSerializer
from .models import NewsCategory, News, Comment


class NewsCategorySerializer(serializers.ModelSerializer):
    class Meta:
        model = NewsCategory
        fields = ('id', 'name', 'sequence')


class NewsSerializer(serializers.ModelSerializer):
    author = CreateUserSerializer(read_only=True)

    class Meta:
        model = News
        exclude = ('content', 'clicks', 'is_delete', 'category')


class CommentSerializer(serializers.ModelSerializer):
    user = CreateUserSerializer(read_only=True)

    class Meta:
        model = Comment
        fields = '__all__'


class NewsDetailSerializer(serializers.ModelSerializer):
    comment = CommentSerializer(many=True, read_only=True)
    author = CreateUserSerializer(read_only=True)

    class Meta:
        model = News
        exclude = ('digest', 'clicks', 'is_delete', 'category')